summaryrefslogtreecommitdiffstats
path: root/src/core/hle/service/time/time_zone_manager.h
blob: 5ebd4035ecc11e2527934c9a5adcfd6e5b82570f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// SPDX-FileCopyrightText: Copyright 2019 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include <string>

#include "common/common_types.h"
#include "core/file_sys/vfs_types.h"
#include "core/hle/service/time/clock_types.h"
#include "core/hle/service/time/time_zone_types.h"

namespace Service::Time::TimeZone {

class TimeZoneManager final {
public:
    TimeZoneManager();
    ~TimeZoneManager();

    void SetTotalLocationNameCount(std::size_t value) {
        total_location_name_count = value;
    }

    void SetTimeZoneRuleVersion(const u128& value) {
        time_zone_rule_version = value;
    }

    void MarkAsInitialized() {
        is_initialized = true;
    }

    Result SetDeviceLocationNameWithTimeZoneRule(const std::string& location_name,
                                                 FileSys::VirtualFile& vfs_file);
    Result SetUpdatedTime(const Clock::SteadyClockTimePoint& value);
    Result GetDeviceLocationName(TimeZone::LocationName& value) const;
    Result ToCalendarTime(const TimeZoneRule& rules, s64 time, CalendarInfo& calendar) const;
    Result ToCalendarTimeWithMyRules(s64 time, CalendarInfo& calendar) const;
    Result ParseTimeZoneRuleBinary(TimeZoneRule& rules, FileSys::VirtualFile& vfs_file) const;
    Result ToPosixTime(const TimeZoneRule& rules, const CalendarTime& calendar_time,
                       s64& posix_time) const;
    Result ToPosixTimeWithMyRule(const CalendarTime& calendar_time, s64& posix_time) const;

private:
    bool is_initialized{};
    TimeZoneRule time_zone_rule{};
    std::string device_location_name{"GMT"};
    u128 time_zone_rule_version{};
    std::size_t total_location_name_count{};
    Clock::SteadyClockTimePoint time_zone_update_time_point{
        Clock::SteadyClockTimePoint::GetRandom()};
};

} // namespace Service::Time::TimeZone